<template>
  <div>
    <MBX level1="订单管理" level2="订单列表"></MBX>
    <el-card class="mt15">
      <!-- 搜索 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 订单列表 -->
      <el-table class="mt15" :data="OrdersData" border>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <div>
              <el-tag :type="typeArr[scope.row.pay_status]">
                {{ scope.row.pay_status | isPay }}</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" width="220">
          <template slot-scope="scope">
            <div>
              {{ scope.row.create_time | dateTime }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div>
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="ModiAddressDia"
              ></el-button>
              <el-button
                type="success"
                size="mini"
                icon="el-icon-location"
                @click="ViewWuLiuDia"
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <!-- 订单分页器 -->
      <el-pagination
        class="mt15"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 修改地址对话框  -->

    <el-dialog title="修改地址" :visible.sync="isModiAddressDia">
      <el-form :model="ModiAddress">
        <el-form-item label="省市区/县" label-width="100px">
          <!-- 省市二级联动 -->
          <el-cascader
            v-model="checkArr"
            :options="CityData"
            :props="defaultProps"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" label-width="100px">
          <el-input v-model="ModiAddress.city" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isModiAddressDia = false">取 消</el-button>
        <el-button type="primary" @click="isModiAddressDia = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <!-- 查看物流进度对话框 -->
    <el-dialog title="物流进度" :visible.sync="isViewWuLiuDia">
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(item, index) in wuLiuData"
          :key="index"
         :color="item.color"
         :icon='item.icon'
          :timestamp="item.time"
        >
          {{ item.context }}
        </el-timeline-item>
      </el-timeline>

      <div slot="footer" class="dialog-footer">
        <el-button @click="isViewWuLiuDia = false">取 消</el-button>
        <el-button type="primary" @click="isViewWuLiuDia = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CityData from "@/mock/city";
import WuLiu from "@/mock/wuliu";
console.log("WuLiu:", WuLiu);
export default {
  name: "orders",
  data() {
      //处理一下物流返回的样式
      WuLiu.data.forEach((item,index) => {
          if(index===0) {
              item.icon='el-icon-s-flag'
              item.color='#ff0000'
              item.size='large'
              item.type='success'
          }
      });

      console.log('WuLiu.data:',WuLiu.data)




    return {
      reverse: false,
      wuLiuData: WuLiu.data,
      //是否显示物流
      isViewWuLiuDia: false,
      //二级联动选中的数组值
      checkArr: [],
      //二级联动配置项
      defaultProps: {
        expandTrigger: "hover",
        label: "label",
        children: "children",
        value: "value",
      },
      ModiAddress: {
        city: "",
      },
      isModiAddressDia: false,
      //省市数据
      CityData,
      typeArr: {
        0: "danger",
        1: "success",
      },
      OrdersData: [],
      pageInfo: {
        //当前默认页码
        pagenum: 1,
        //每页显示的条数
        pagesize: 5,
      },
      //总条数
      total: 0,
    };
  },
  created() {
    this.getOrdersList();
  },
  methods: {
    //查看物流进度
    ViewWuLiuDia() {
      this.isViewWuLiuDia = true;
    },
    ModiAddressDia() {
      this.isModiAddressDia = true;
    },
    //二级联动数据改变后触发
    handleChange() {
      console.log("二级联动数据改变后触发");
    },
    //每页条数改变时触发
    handleSizeChange(val) {
      this.pageInfo.pagesize = val;
      //刷新订单列表
      this.getOrdersList();
    },
    //当前页码改变时触发
    handleCurrentChange(val) {
      this.pageInfo.pagenum = val;
      //刷新订单列表
      this.getOrdersList();
    },
    //获取订单列表
    async getOrdersList() {
      //调用订单列表接口
      const res = await this.$API.getGoodsOrdersListAPI(this.pageInfo);
      console.log("订单数据：", res);
      let { goods, total } = res;
      this.OrdersData = goods;
      this.total = total;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-cascader,
.el-input {
  width: 80%;
}
</style>
